/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */
package com.ruoyi.mall.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.mall.api.RemoteShoppingCartService;
import com.ruoyi.mall.api.entity.ShoppingCart;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 购物车
 *
 * @author JL
 * @date 2019-08-29 21:27:33
 */
@Slf4j
@RestController
@RequestMapping("/shoppingcart")
@Api(value = "shoppingcart", tags = "购物车管理")
public class ShoppingCartController extends BaseController {
    @DubboReference
    private RemoteShoppingCartService shoppingCartService;

    /**
     * 分页查询
     *
     * @param page         分页对象
     * @param shoppingCart 购物车
     * @return
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @SaCheckPermission("mall:shoppingcart:index")
    public R getShoppingCartPage(Page page, ShoppingCart shoppingCart) {
        return R.ok(shoppingCartService.page(page, shoppingCart));
    }

    /**
     * 通过id查询购物车
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id查询购物车")
    @GetMapping("/{id}")
    @SaCheckPermission("mall:shoppingcart:get")
    public R getById(@PathVariable("id") String id) {
        return R.ok(shoppingCartService.getById(id));
    }

    /**
     * 新增购物车
     *
     * @param shoppingCart 购物车
     * @return R
     */
    @ApiOperation(value = "新增购物车")
    @PostMapping
    @SaCheckPermission("mall:shoppingcart:add")
    public R save(@RequestBody ShoppingCart shoppingCart) {
        return R.ok(shoppingCartService.save(shoppingCart));
    }

    /**
     * 修改购物车
     *
     * @param shoppingCart 购物车
     * @return R
     */
    @ApiOperation(value = "修改购物车")
    @PutMapping
    @SaCheckPermission("mall:shoppingcart:edit")
    public R updateById(@RequestBody ShoppingCart shoppingCart) {
        return R.ok(shoppingCartService.updateById(shoppingCart));
    }

    /**
     * 通过id删除购物车
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id删除购物车")
    @DeleteMapping("/{id}")
    @SaCheckPermission("mall:shoppingcart:del")
    public R removeById(@PathVariable String id) {
        return R.ok(shoppingCartService.removeById(id));
    }

}
